<template>
  <div class="greeting">
    <div class="al-top-block">
      <el-button type="primary" size="mini" @click="toPage('greet-add')">新建全局欢迎语</el-button>
      <span class="tips">「全局欢迎语」优先级小于 「员工活码」欢迎语</span>
    </div>

    <wx-table :test-data="tableDta" :labels="tabLabels" :controls="controls" :sticky="true"
              searchApi="/wxqy/greet/list"
              :contro-fun="operationControl">
      <template #welcome="{param}">
        <wx-multimedia-card :mulimedia="param.welcome"/>
      </template>
      <template #users="{param}">
        <wx-tooltip :line="4">
          <wx-link tag v-for="(e,i) in param.users" :key="i">{{ e.name }}</wx-link>
        </wx-tooltip>
      </template>
    </wx-table>
  </div>
</template>

<script>
import WxLink from "@/components/wxqy/wxLink/wxLink";
import WxTable from "@/components/wxqy/table/WxTable";
import WxTooltip from "@/components/wxqy/wxTooltip/wxTooltip";
import WxMultimediaCard from "@/components/wxqy/wxMultimediaCard/wxMultimediaCard";

export default {
  name: "greeting",
  components: {WxMultimediaCard, WxTable, WxTooltip, WxLink},
  data() {
    return {
      tabLabels: [{label: '标题', prop: 'title', width: '140', tooltip: true},
        {label: '消息内容', prop: 'welcome'},
        {label: '使用员工', prop: 'users'},
        {label: '创建人', prop: 'creatorName', width: '100'},
        {label: '最近更新时间', 'prop': 'modifyTime', width: '180'}],
      controls: [{label: '编辑', type: 'primary'},
        {label: '统计', type: 'primary'},
        {label: '删除', type: 'danger'}],
      tableDta: null
    }
  },
  methods: {
    toPage(path, id) {
      this.$router.push({path: path, query: {id}})
    },
    deleteGreet(row) {
      this.$confirm(`是否删除「${row.title}」`, '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        this.$message({
          type: 'success',
          message: '删除成功!'
        });
      })
    },
    operationControl(row, index) {
      if (index === 0) {
        this.toPage('greet-add', row.id)
      } else if (index === 1) { //统计

      } else { //删除
        this.deleteGreet(row)
      }
    }
  },
  created() {}
}
</script>

<style scoped lang="scss">
.greeting {
  margin: 20px;
  height: calc(100% - 120px);
  overflow-y: visible;
}

.al-top-block {
  padding-bottom: 20px;
}

.tips {
  font-size: 12px;
  margin-left: 10px;
  color: #ae7205;
}

::v-deep .WxTable {
  border-radius: 14px;
}
</style>
